/*
 * @(#)org.example 2020/3/24/0024
 *
 * Copy Right@ 人人译视界
 */


package org.example;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * <pre>
 * @author tuwei
 *
 * @version 0.9
 *
 * 修改版本: 0.9
 * 修改日期: 2020/3/24/0024
 * 修改人 :  tuwei
 * 修改说明: 初步完成
 * 复审人 ：
 * </pre>
 */
public class FileChannelDemo {
	public static void main(String[] args) throws IOException {
		String msg = "hello world";
		FileOutputStream fis = new FileOutputStream(new File("d:\\workspaces\\nio-demo\\test.txt"));
		FileChannel fc = fis.getChannel();
		ByteBuffer buffer = ByteBuffer.allocate(1024);
		buffer.put(msg.getBytes());
		// 写完buffer后，需要反转当前buffer
		buffer.flip();
		fc.write(buffer);
		fis.close();
	}
}